/* Copyright 2009
 *
 * This program and the accompanying materials
 * are made available under the terms of the
 * Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in
 * writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * Contributors:
 * 	   IBM Corporation - initial API and implementation for JDT/DLTK
 *     Sean W. Quinn - initial adoption for use with PHP from various sources.
 */
package org.eclipse.php.internal.core;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.php.core.IPharEntryResource;

public class PharEntryDirectory extends PharEntryResource {
	private IPharEntryResource[] children;

	public PharEntryDirectory(String simpleName) {
		super(simpleName);
	}

	@Override
	public PharEntryResource clone(Object newParent) {
		PharEntryDirectory dir = new PharEntryDirectory(this.simpleName);
		dir.setParent(newParent);
		int length = this.children.length;
		if (length > 0) {
			IPharEntryResource[] newChildren = new IPharEntryResource[length];
			for (int i = 0; i < length; i++) {
				PharEntryResource child = (PharEntryResource) this.children[i];
				newChildren[i] = child.clone(dir);
			}
			dir.setChildren(newChildren);
		}
		return dir;
	}

	public IPharEntryResource[] getChildren() {
		return this.children;
	}

	public InputStream getContents() throws CoreException {
		return new ByteArrayInputStream(new byte[0]);
	}

	public boolean isFile() {
		return false;
	}

	public void setChildren(IPharEntryResource[] children) {
		this.children = children;
	}

	@Override
	public String toString() {
		return "PharEntryDirectory[" + getEntryName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
	}
}
